package com.itheima.health.controller;

import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "权限管理")
public class PermissionController {
    @Reference
    private PermissionService permissionService;

    @PostMapping("permission/findByPage")
    @ApiOperation(value = "分页查询功能",notes = "查询权限列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        //    分页查询  条件  页码  记录数  条件
        //  集合 插件  PageResult对象
        return new Result(permissionService.findPage(queryPageBean));
    }

    @GetMapping("permission/findAll")
    @ApiOperation(value = "查询所有",notes = "查询权限列表信息")
    public Result findAll(){
        //    分页查询  条件  页码  记录数  条件
        //  集合 插件  PageResult对象
        return new Result(permissionService.list());
    }

    @PostMapping("permission/saveOrUpdate")
    @ApiOperation(value = "新增和修改权限，有id就是新增，没有就是修改",notes = "新增和修改权限")
    public Result saveOrUpdate(@RequestBody Permission permission){
        return new Result(permissionService.saveOrUpdate(permission));
    }

    @DeleteMapping("permission/deleteById/{id}")
    @ApiOperation(value = "根据id删除权限",notes = "删除权限")
    public Result deleteById(@PathVariable Integer id){
        return new Result(permissionService.removeById(id));
    }

}
